#!/bin/bash

# Check if there's input from pipe or redirection
if [ -t 0 ]; then
  # No input from pipe, use first argument or default
  commit_message="${1:-Backup commit on $(date)}"
else
  # Read commit message from stdin (pipe or redirection)
  commit_message=$(cat)
fi

# Navigate to the repository directory (optional)
# cd /path/to/your/repository

# Stage all changes
git add .

# Commit with the provided or default message
git commit -m "$commit_message"

# Check if the remote 'origin' already exists
if ! git remote | grep -q "^origin$"; then
  # If it doesn't exist, add it
  git remote add origin git@gitee.com:recursivejiashuo/temp-event-clframe.git
fi

git push -u origin master --verbose

# Print a success message
echo "Code changes backed up successfully!"
